package org.arch_learn.rpc.provider2.service;

import org.arch_learn.rpc.nz_rpc.annos.RpcService;
import org.arch_learn.rpc.nz_rpc_api.pojo.User;
import org.arch_learn.rpc.nz_rpc_api.service.IUserService;
import org.springframework.beans.factory.annotation.Value;

import java.util.HashMap;
import java.util.Map;

@RpcService
public class UserService implements IUserService {
    private static Map<Integer, User> users;

    @Value("${spring.application.name}")
    private String applicationName;

    static {
        users = new HashMap<Integer, User>() {{
            put(1, new User(1, "张三2"));
            put(2, new User(2, "李四2"));
        }};
    }

    @Override
    public User findById(Integer id) {
        System.out.println(applicationName + "正在响应。。。");
        return users.get(id);
    }

    @Override
    public void addUser(User user) {
        users.put(user.getId(), user);
    }
}
